package com.slz3.business.module.configManagement.conShareManage.service;

import com.slz3.business.frame.enums.ValidFlag;
import com.slz3.business.frame.module.Repositorys;
import com.slz3.business.frame.module.Services;
import com.slz3.business.frame.steward.PageableSteward;
import com.slz3.business.module.configManagement.conShareManage.domain.ConShareManage;
import com.slz3.business.module.configManagement.conShareManage.domain.ConShareManageFactory;
import com.slz3.business.module.configManagement.conShareManage.steward.ConShareManageSpecification;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.util.MultiValueMap;

import java.util.*;

@Slf4j
@Service
public class ConShareManageServiceImpl implements ConShareManageService {
    @Override
    public ConShareManage save(ConShareManage conShareManage) {
        return Repositorys.conShareManage.save(ConShareManageFactory.initBaseFields(conShareManage));
    }
    @Override
    public Page<ConShareManage> page(MultiValueMap<String, String> params) {
        Page<ConShareManage> conShareManagePage = Repositorys.conShareManage.findAll(
                ConShareManageSpecification.findJoin(params), PageableSteward.extract(params)
        );
        return conShareManagePage;
    }


    @Override
    public ConShareManage modify(ConShareManage conShareManageNew) {
        return Repositorys.conShareManage.saveAndFlush(ConShareManageFactory.initBaseFields(conShareManageNew));
    }

    @Override
    public Optional<ConShareManage> single(UUID uuid) {
        return Repositorys.conShareManage.findById(uuid);
    }

    @Override
    public List<ConShareManage> findAllByUuids(Iterable<UUID> uuids) {
        return Repositorys.conShareManage.findAllById(uuids);
    }

    @Override
    public List<ConShareManage> delete(List<ConShareManage> conShareManageList) {
        conShareManageList.stream().forEach(item -> {
            item.setValidFlag(ValidFlag.DEL);
            ConShareManageFactory.initBaseFields(item);
        });
        return Services.conShareManageTransactional.batchModify(conShareManageList);
    }

}
